var express = require('express');
var router = express.Router();
var User = require('../dao/user');

//regist routers
router.get('/regist', function(req, res, next) {
    res.render('regist');
})

router.post('/regist', function(req, res, next) {
    User.save(req.body, get)
    function get(result) {
        res.send(result);
    }
})

//login routers
router.get('/login', function(req, res, next) {
    res.render('login');
})

router.post('/login', function(req, res, next) {
    sess = req.session;
    User.get(req.body, get);
    function get(result) {
        if(result.loginStatus == 1) {sess.user = req.body.username;}
        else sess.user = null;
        res.send(result);
    }
})

module.exports = router;
